﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Collections;

namespace CXMLStudioIDE.Forms
{
    public partial class NewFileForm : Form
    {
        Form m_parent;
        public const string sZ_TextFile = "TextFile";
        public const string sZ_GodlFormDesign = "GoldForm Design";
        public const string sZ_GodlFormEntry = "GoldForm Entry";

        public NewFileForm(Form parent)
        {
            m_parent = parent;
            InitializeComponent();
            tvCategories.SelectedNode = tvCategories.Nodes[0];
            tvCategories_NodeMouseClick(tvCategories,new TreeNodeMouseClickEventArgs(tvCategories.SelectedNode,MouseButtons.Left,0,0,0));
        }

        private void tvCategories_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
        {
            ListViewItem lvi;
            switch (e.Node.Name)
            { 
                case "General":
                        lvTemplates.Clear();
                        lvi = new ListViewItem("Text File");
                        lvi.Name = sZ_TextFile;
                        lvi.ImageIndex = 11;
                        lvTemplates.Items.Add(lvi);
                    break;
                case "Gold":
                        lvTemplates.Clear();
                        lvi = new ListViewItem("Gold Form Design");
                        lvi.Name = sZ_GodlFormDesign;
                        lvi.ImageIndex = 10;
                        lvTemplates.Items.Add(lvi);
                        lvi = new ListViewItem("Gold Form Entry");
                        lvi.Name = sZ_GodlFormEntry;
                        lvi.ImageIndex = 10;
                        lvTemplates.Items.Add(lvi);
                    break;
            }
        }

        private void lvTemplates_SelectedIndexChanged(object sender, EventArgs e)
        {
            ListView lv = (ListView)sender;
            if (lv != null)
            {
                if(lv.SelectedItems.Count > 0)
                {
                    switch (lv.SelectedItems[0].Name)
                    {
                        case sZ_TextFile:
                            lblInfo.Text = "Normal Text File or RTF";
                            break;
                        case sZ_GodlFormDesign:
                            lblInfo.Text = "Gold Form design using Form Designer";
                            break;
                        case sZ_GodlFormEntry:
                            lblInfo.Text = "Gold Form Entry";
                            break;
                    }
                }
            }
        }

        private void tvCategories_MouseClick(object sender, MouseEventArgs e)
        {
            lblInfo.Text = "";
        }

        private void btnOpen_Click(object sender, EventArgs e)
        {
            if (lvTemplates.SelectedItems.Count > 0)
            {
                switch (lvTemplates.SelectedItems[0].Name)
                {
                    case sZ_TextFile:
                        this.Close();
                        ((MainForm)m_parent).NewTextFile(null);
                        break;
                    case sZ_GodlFormDesign:
                        this.Close();
                        ((MainForm)m_parent).NewFormDesignerForm();
                        break;
                    case sZ_GodlFormEntry:
                        this.Close();
                        ((MainForm)m_parent).NewGoldEntryForm(null,null,null,AddInstanceForm.AddInstanceMode.None);
                        break;
                }
            }
            else {
                MessageBox.Show("Please select an item", "CXMLStudio", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
            this.Dispose();
        }

        private void tvCategories_AfterSelect(object sender, TreeViewEventArgs e)
        {

        }
    }
}
